package org.ccahouse.ccatrain.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.ccahouse.ccacommons.base.BaseController;
import org.ccahouse.ccacommons.common.RestResult;
import org.ccahouse.ccatrain.dto.HospitalDto;
import org.ccahouse.ccatrain.dto.HospitalListPageDto;
import org.ccahouse.ccatrain.entity.Hospital;
import org.ccahouse.ccatrain.service.impl.HospitalServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hospital")
@Api(tags = "医院信息")
public class HospitalController extends BaseController {
    @Autowired
    private HospitalServiceImpl hospitalService;

    @GetMapping("/page")
    @ApiOperation(value = "分页列表", response = Hospital.class)
    public RestResult getHospitalPage(HospitalListPageDto hospitalListPageDto){
        return  hospitalService.getHospitalPage(hospitalListPageDto);
    }

    @GetMapping("/list")
    @ApiOperation(value = "所有列表", response = Hospital.class)
    public RestResult getHospitalList(){
        return  hospitalService.getHospitalList();
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存数据", response = RestResult.class)
    public RestResult saveHospital(Hospital hospital){
        return  hospitalService.saveHospital(hospital);
    }

    @PostMapping("/saveBatch")
    @ApiOperation(value = "保存多条数据", response = RestResult.class)
    public RestResult saveHospital(@RequestBody List<Hospital> hospitals){
        return  hospitalService.saveHospitals(hospitals);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "获取单条数据", response = Hospital.class)
    public RestResult getOne(@PathVariable Integer id){
        return hospitalService.getOneById(id);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新医院名称", response = RestResult.class)
    public RestResult updateHospital(@RequestBody HospitalDto hospital){
        return  hospitalService.updateHospital(hospital);
    }

    @PostMapping("/getByIds")
    @ApiOperation(value = "ids查询", response = Hospital.class)
    public RestResult getHospitalByIds(@RequestBody List<Integer> ids){
        return  hospitalService.getHospitalByIds(ids);
    }

}
